<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="项目名称" class="row-padding-bottom">
              <el-input
                v-model="filterField.projectName"
                placeholder="请输入项目名称"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="区域" class="row-padding-bottom">
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                clearable
                filterable
                :props="{ checkStrictly: true }"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="行业" class="row-padding-bottom">
                <el-select
                  v-model="filterField.industryId"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in industryOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="专户账号" class="row-padding-bottom">
                <el-input
                  v-model="filterField.account"
                  placeholder="请输入专户账号"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="开户银行" class="row-padding-bottom">
                <el-select
                  v-model="filterField.bankId"
                  filterable
                  placeholder="请选择开户银行"
                  clearable
                >
                  <el-option
                    v-for="item in bankOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="是否签约" class="row-padding-bottom">
                <el-select
                  placeholder="请选择"
                  clearable
                  v-model="filterField.signed"
                >
                  <el-option label="是" value="1"></el-option>
                  <el-option label="否" value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
              <exportBtn
                :dataLen="tableList.length"
                :filterField="filterField"
                api="api-s/report/export_YH_SALARY_AGENCY_MAINTENANCE"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column prop="projectName" label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="areaName"
            label="所属区域"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="industryName"
            label="行业"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column prop="signed" label="是否签约" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.signed == 1">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="isCancellation"
            label="是否销户"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.isCancellation == 1">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="bankName"
            label="开户银行"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            label="专户账号"
            align="center"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.account | deseHandler(4, 4, '*') || '--' }}</p>
            </template>
          </el-table-column>
          <el-table-column label="应发/到账工资总额(元)" min-width="200">
            <template slot-scope="scope">
              <p>
                ￥{{ scope.row.shouldPay || '0' }}/￥{{
                  scope.row.bankActPay || '0'
                }}
              </p>
            </template>
          </el-table-column>
          <el-table-column label="应发/到账总人次" min-width="180">
            <template slot-scope="scope">
              <p>
                {{ scope.row.shouldPayTotal || '0' }}/{{
                  scope.row.bankActPayTotal || '0'
                }}
              </p>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="left"
            fixed="right"
            min-width="120"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="isShowDetail"
                @click="toDetail(scope.$index, scope.row)"
                >查看详情</el-link
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>
<script>
import scrollTable from '@/mixin/scrollTable.js'
import { mapActions, mapState } from 'vuex'
export default {
  name: 'czSalaryPayList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '工资代发',
      advanced: false,
      dialogVisible: false,
      //表格数据
      tableList: [],
      requestUrl: 'api-su/cs/salarystats/expand/list',
      areaId: '',
      bankOptions: [],
      //搜索条件
      filterField: {
        projectName: '', //项目名称
        areaId: '', //区域
        industryId: '', //行业
        account: '', //专户账号
        bankId: '', //银行
        signed: '', //是否签约
      },
      isShow: false, //列表加载
      loading: true,
      isShowDetail: '',
      bankId: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptions']) },

  created() {
    this.getBank()
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.getUserType()
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.getIndustry({})
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('bankSalaryPayList:detail') >
        -1 ||
      this.$store.state.buttonLimitsArr.indexOf('mCsSalaryList:detail') > -1
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    ...mapActions(['getAreas', 'getIndustry']),
    getBank() {
      var data = {
        type: 'BANK_TYPE',
      }
      this.axios({
        method: 'post',
        url: 'api-bs/base/dicitem/findbytype',
        data: data,
      })
        .then((response) => {
          this.bankOptions = []
          for (let i = 0; i < response.data.result.length; i++) {
            let bank = response.data.result[i]
            if (this.bankId == bank.code) {
              this.bankOptions.push(bank)
            }
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },

    // 搜索
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //跳转详情
    toDetail(index, row) {
      this.$router.push({
        path: '/home/salaryDf/czSalaryPayBatchList',
        name: 'czSalaryPayBatchList',
        query: {
          projectId: row.projectId,
          projectName: row.projectName,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/salaryDf/czSalaryPayList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getUserType() {
      this.axios({
        method: 'get',
        url: 'api-u/users/current',
      })
        .then((response) => {
          //用户类型
          this.bankId = response.data.bankId
          this.getBank()
        })
        .catch((resp) => {})
    },
  },
}
</script>

<style scoped lang="less">
@import '../../../static/css/filterArea.less';
.topTitle {
  height: 67px;
  background-color: #e4ebf1;
  padding-left: 24px;
  font: bold 18px/67px Microsoft YaHei;
}
.mainCon {
  top: 198px;
}
@media only screen and (max-width: 1366px) {
  /deep/.searchInputWidth .el-form--inline .el-form-item__label {
    width: 80px;
  }
}
</style>
